package com.skplanet.oneplusonewindow.moimserver.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnore;

@Entity
@Table( name = "MOIM_USER" )
public class Moim_User{

	public List<Moim_Moim> getMoims() {
		return moims;
	}

	public void setMoims(List<Moim_Moim> moims) {
		this.moims = moims;
	}

	public void addMoim(Moim_Moim moim) {
		if(this.moims == null)
			this.moims = new ArrayList<Moim_Moim>();
		this.moims.add(moim);
	}
	
	public Moim_Moim getMoim(long moimId) {
		int size = moims.size();
		for(int i = 0 ; i < size ; i ++)
			if(moims.get(i).getId() == moimId)
				return moims.get(i);
		return null;
	}
	
	
	public final static String PREFIX_NUMBER_USERID = "1";
	

	public Moim_User(){
		this.setCreateDate(new Date());
		this.setUpdateDate(new Date());
	}

	public Moim_User(long id) {
		this.id = id;
	}
	/**
	 *  기본정보
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private long id;
	
	@Column( name="nickname", length=50 )
	private String nickname;
	
	@Column( name="name", length=40 )
	private String name;

	@Column( name="password", length=64 )
	@JsonIgnore
	private String password;

	@Column( name="salt", length=64 )
	@JsonIgnore
	private String salt;

	@Column(name = "authority")
	private String authority;

	@Column(name = "create_date")
	private Date createDate;
	
	@Column(name = "update_date")
	protected Date updateDate;
	
	@ManyToMany(mappedBy = "users", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	@OrderBy("id ASC" )
	private List<Moim_Moim> moims;
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public String getAuthority() {
		return authority;
	}

	public void setAuthority(String authority) {
		this.authority = authority;
	}



}